package util;


import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


public class TxtUtil {

    /**
     * 读入TXT文件
     */
    public static ArrayList<ArrayList<Object>>  readFile(String url) {
    	ArrayList<ArrayList<Object>> ans = new ArrayList<ArrayList<Object>>();
    	ArrayList<Object> cowList;
        String pathname = url; 
        try (FileInputStream fis = new FileInputStream(pathname);
        	InputStreamReader isr = new InputStreamReader(fis,"GBK");
             BufferedReader br = new BufferedReader(isr) // 建立一个对象，它把文件内容转成计算机能读懂的语言
        ) {
            String line;
            //网友推荐更加简洁的写法
            while ((line = br.readLine()) != null) {
            	cowList = new ArrayList();
                // 一次读入一行数据
            	String[] temp = line.split("[\\s\\p{Zs}]");
            	for(int i = 0; i < temp.length; i++) {
            		cowList.add(temp[i]);
            	}
            	ans.add(cowList);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return ans;
    }
}


